// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'

//引入根组件(App.vue)
import App from './App'

// 引入router(router需要挂载在vue实例中)
import router from './router/router.js'

// 引入elementUI
import ElementUI from 'element-ui'

//element UI的样式
// import 'element-ui/lib/theme-chalk/index.css'

//引入全局的css
import './assets/css/com.css'

// 引入axios
import axios from 'axios'

// 引入ElTreeGrid
import ElTreeGrid from 'element-tree-grid'
Vue.component(ElTreeGrid.name, ElTreeGrid)

// 设置axios基路径
axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'

// 将axios添加到Vue的原型上
Vue.prototype.$axios = axios

// 设置全局的token,只需要加上这个,后面的就不用添加请求头
// axios.defaults.headers.common['Authorization'] = localStorage.getItem('token')

// 添加请求拦截器
axios.interceptors.request.use(
  config => {
    // 每次在请求之前携带token
    config.headers.Authorization = localStorage.getItem('token')
    return config
  },
  error => {
    // 对请求错误做些什么
    return Promise.reject(error)
  }
)

//用vue安装一下
Vue.use(ElementUI)

//提示开发环境
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  //index.html中的#app
  el: '#app',
  //挂载路由
  router,
  components: { App },
  //根组件中的#app,页面实际是展示在template中的
  template: '<App/>'
})
